package servcie;

import domain.Student;
import domain.Task;
import domain.Teacher;
import java.util.ArrayList;
import java.util.Scanner;

public class StudentTask extends TaskScheduleImpl{
     private final Teacher teacher;
     private final ArrayList<Student> arrayList;
     private final Scanner scanner;
     private Student student;
    public StudentTask(Teacher teacher,ArrayList<Student> students,Scanner scanner) {
        this.teacher = teacher;
        this.arrayList=students;
        this.scanner=scanner;
    }
    private void fillInTask(Student student){
        Task task=new Task();
        String txt="每日总结需完成百分比:";
        System.out.println("请输入"+txt+"数据%");
        String pinjie=scanner.next();
        task.setConclusion(txt+pinjie);
        txt="每日作业需完成百分比:";
        System.out.println("请输入"+txt+"数据%");
        pinjie=scanner.next();
        task.setHomeWork(txt+pinjie);
        txt="每日预习需完成百分比:";
        System.out.println("请输入"+txt+"数据%");
        pinjie=scanner.next();
        task.setPreview(txt+pinjie);
        student.setTask(task);
        student.setFlag(true);
    }       //填写任务进度

    public Student getTeamMember(){
        String sel=scanner.next();
        for (Student student : arrayList) {
            if (student.getStuId().equals(sel)){
                return student;
            }
        }

        return null;
    }    //根据学号找到学生对象
    @Override
    public void task() {
        while (true){
            System.out.println("---------欢迎进入学生系统---------");
            System.out.println("1 查看老师派发任务");
            System.out.println("2 填写任务完成进度");
            System.out.println("3 退出学生管理系统");
            if (student==null){
                System.out.println("请输入您的学号:");
                student=getTeamMember();
                while (student==null){
                    System.out.println("当前学号对应的学生不存在,请重新录入...");
                    student=getTeamMember();
                }
            }
            System.out.println("请输入您的选择:");
            int select=scanner.nextInt();
            switch (select){
                case 1:
                    if (teacher.isFlag()){
                        viewTask(teacher);
                    }else {
                        System.out.println("老师未下发任务!");
                    }
                    break;
                case 2:
                    if (teacher.isFlag()){
                        fillInTask(student);
                    }else {
                        System.out.println("老师未下发任务!");
                    }
                    break;
                case 3:
                    return;
                default:
                    System.out.println("乱输十八？扇你");
            }
        }


    }
}
